package net.happy2v.file.server.test.file;

import java.net.InetSocketAddress;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import net.happy2v.file.server.test.file.factory.FileServerMainFactory;
import net.happy2v.file.server.test.file.impl.FileImpl;
import net.ib.rpc.method.MethodInfos;
import net.ib.rpc.util.SysException;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

public class FileServerTestMain {

	private MethodInfos services;

	public FileServerTestMain(){
		this.services = new MethodInfos();
		try {
			services.addService(new FileImpl());
		} catch (SysException e) {
			e.printStackTrace();
		}
	}

	public void run() {
		// Configure the bootstrap.
		// 부트스트랩 설정
		Executor executor = Executors.newCachedThreadPool();
		ServerBootstrap sb = new ServerBootstrap(
				new NioServerSocketChannelFactory(executor, executor));

		// Set up the event pipeline factory.
		// 이벤트 파이프 라인 팩토리 설정
		sb.setPipelineFactory(new FileServerMainFactory(services));

		// Start up the server.
		// 서버 시작
		sb.bind(new InetSocketAddress(7777));
	}

	public static void main(String[] args) throws Exception {
		new FileServerTestMain().run();
	}
}